import vue from 'vue'
import store from '../store/index'
import StringUtils from '../utils/StringUtils'
import xurl from "./xurl";
import XDebug from "./XDebug";
//确认采购参数
let CONFIRMPROCUREPARAM = 'CONFIRMPROCUREPARAM_OS'

export default {
    /**
     * 获得确认采购参数
     */
    getConfirmProcureParam() {
        let procureParam = sessionStorage.getItem(CONFIRMPROCUREPARAM)
        if (!!procureParam && procureParam != 'undefined' && procureParam != 'null') {
            return JSON.parse(window.decodeURIComponent(procureParam))
        }
        return null;
    },
    /**
     * 更新确认采购参数
     * @param params
     */
    updateConfirmProcureParam(params) {
        sessionStorage.setItem(CONFIRMPROCUREPARAM, encodeURIComponent(JSON.stringify(params)))
    },
    //更新更换款式保存信息
    updateConfirmProcure(confirmProcure) {
        let params = this.getConfirmProcureParam();
        if (params != null) {
            params.confirmProcure = confirmProcure;
            this.updateConfirmProcureParam(params);
        }
    },
    /**
     * 更新确认采购参数 for 提货人
     * @param params
     */
    updateConfirmProcureParam4Delivery() {
        if (!!store.state.currentUser) {
            let confirmProcureParam = this.getConfirmProcureParam();
            if (!confirmProcureParam || confirmProcureParam == null) {
                confirmProcureParam = {}
            }
            if (!!confirmProcureParam.curDeliveryId || StringUtils.isBlank(confirmProcureParam.deliveryName)
                    || StringUtils.isBlank(confirmProcureParam.deliveryPhone)) {
                xurl.postSync(vue.prototype.NW_API_vue + '/getDefault/pickupPerson').then(data => {
                    if (data.success) {
                        confirmProcureParam.deliveryName = data.result.deliveryName
                        confirmProcureParam.deliveryPhone = data.result.deliveryPhone
                        confirmProcureParam.curDeliveryId = data.result.curDeliveryId
                        this.updateConfirmProcureParam(confirmProcureParam)
                    } else {
                        console.log('updateConfirmProcureParam4Delivery error : ' + data.errMsg)
                    }
                })
            }
        }
    }
}
